# Maintainer: Doug Massay

pkgname=sigil
_commit=%COMMIT%
pkgver=$_commit
pkgrel=1
pkgdesc='multi-platform EPUB2/EPUB3 ebook editor'
arch=('x86_64')
url="https://github.com/Sigil-Ebook/Sigil"
license=(GPL3)
depends=(hicolor-icon-theme
         hunspell
         mathjax
         minizip
         python-css-parser
         python-dulwich
         python-lxml
         qt6-svg
         qt6-webengine)
makedepends=(cmake
             qt6-tools)
optdepends=('hunspell-en_US: for English dictionary support'
            'hyphen-en: for English hyphenation support in plugins'
            'pageedit: external editor to replace BookView'
            'pyside6: recommended for plugins'
            'python-html5lib: recommended for plugins'
            'python-chardet: recommended for plugins'
            'python-cssselect: recommended for plugins'
            'python-pillow: recommended for plugins'
            'python-regex: recommended for plugins'
            'tk: recommended for plugins')
_archive="${pkgname^}-$pkgver"
source=("git+$url.git#commit=$_commit")
sha512sums=('SKIP')

prepare() {
	cd "$_archive
    mkdir -p build
}

build() {
	cd "$_archive/build"
	cmake -G "Unix Makefiles" \
		-D USE_SYSTEM_LIBS=1 \
		-D SYSTEM_LIBS_REQUIRED=1 \
		-D INSTALL_BUNDLED_DICTS=0 \
		-D INSTALL_HICOLOR_ICONS=1 \
		-D DISABLE_UPDATE_CHECK=1 \
		-D MATHJAX3_DIR=/usr/share/mathjax \
		-D CMAKE_INSTALL_PREFIX=/usr \
		-D CMAKE_INSTALL_LIBDIR=lib \
		-D CMAKE_C_FLAGS="$CFLAGS" \
		-D CMAKE_CXX_FLAGS="$CXXFLAGS" \
		-D CMAKE_SKIP_RPATH=ON ..
	make
}

package() {
	cd "$_archive/build"
	make install DESTDIR="$pkgdir"
	python -m compileall "$pkgdir/usr/share/sigil/"{plugin_launchers/python/,python3lib}
	python -O -m compileall "$pkgdir/usr/share/sigil/"{plugin_launchers/python/,python3lib}
}
